package vk;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * User: ekozobrodov
 */
class RequestHelper {
    private static final String API_URL = "https://api.vk.com/method/";

    public static String doGet(String methodName, String query) {
        URL url;
        HttpURLConnection conn;
        BufferedReader rd;
        String line;
        String result = "";
        try {
            url = new URL(API_URL + methodName + ".xml?" + query + "&access_token=" + AuthComponent.getAccessToken());
            System.out.println(url);
            conn = (HttpURLConnection)url.openConnection();
            conn.setRequestMethod("GET");
            rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
             while ((line = rd.readLine()) != null) {
                result += line;
             }
             rd.close();
        } catch (IOException e) {
            return null;
        }
        return result;
    }
}
